home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / amicad / arexx_english / grid.amicad < prev    next >
Text File  |  1998-08-09  |  4KB  |  180 lines

  1. /* Creates a grid in the current window.
  2. $VER: 1.02e (© R.Florac, 9 août 1998) */
  3.  
  4. options results
  5.  
  6. signal on error
  7. signal on syntax
  8.  
  9. 'WWIDTH(-1)'; lt = result
  10. 'WHEIGHT(-1)'; ht=result
  11. clip=-1
  12. FIRSTSEL; obj=result
  13. if obj>0 then do
  14.     'TYPE(FIRSTSEL)'; type=result
  15.     if type=22 then do
  16.     'CLIPUNIT(5)'; clip=result
  17.     'COORDS(FIRSTSEL)'; coords=result
  18.     PARSE VAR coords x0 ',' y0 ',' x1 ',' y1
  19.     xg=minima(x0,x1); xd=maxima(x0,x1)
  20.     yh=minima(y0,y1); yb=maxima(y0,y1)
  21.     l=xd-x0+1; h=yb-y0+1
  22.     'NEXTSEL('obj')'; obj=result
  23.     end
  24. end
  25. else obj=1
  26.  
  27. if obj>0 then do
  28.     'MESSAGE("Draw and select a"+CHR(10)+"box, the grid will"+CHR(10)+"be included in it.")'
  29.     call quitter
  30. end
  31.  
  32. 'ASK("Horizontal axis"+CHR(10)+"Number of decades?")'
  33. ndh = result
  34. if ndh<=0 then call quitter
  35. 'SELECT("Scale type"+CHR(10)+"1- Linear"+CHR(10)+"2- Logarithm"+CHR(10)+"3- Antilog")'
  36. tt=result
  37. y1=y0+h
  38. x1=x0+ndh*(l%ndh)
  39.  
  40. 'SAVEALL(-1)'
  41. if clip>=0 then 'MENU("Cut")'
  42. /* Vertical lines */
  43. select
  44.     when tt=1 then do
  45.     do i=1 to ndh
  46.         x2 = (x0)+i*(l/ndh)
  47.         x2 = x2%1
  48.         'DRAWMODE(-1)'
  49.         do c=1 to 9
  50.         xc = x2-(l/ndh)/10*c
  51.         xc=xc%1
  52.         'DRAW('xc','y0','xc','y1')'
  53.         end
  54.         'DRAWMODE(-2):DRAW('x2','y1','x2','y0')'
  55.     end
  56.     end
  57.     when tt=2 then do
  58.     if ~show('L','rexxmathlib.library') then
  59.        call addlib('rexxmathlib.library',0,-30)
  60.     x2=x0
  61.     do i=1 to ndh
  62.         'DRAWMODE(-1)'
  63.         do c=2 to 9
  64.         xc=(l/ndh)*log10(c)
  65.         xc=(x2+xc)%1
  66.         'DRAW('xc','y0','xc','y1')'
  67.         end
  68.         x2 = (x0)+i*(l/ndh)
  69.         x2 = x2%1
  70.         'DRAWMODE(-2):DRAW('x2','y1','x2','y0')'
  71.     end
  72.     end
  73.     when tt=3 then do
  74.     if ~show('L','rexxmathlib.library') then
  75.        call addlib('rexxmathlib.library',0,-30)
  76.     x2=x1
  77.     do i=1 to ndh
  78.         'DRAWMODE(-2):DRAW('x2','y1','x2','y0')'
  79.         'DRAWMODE(-1)'
  80.         do c=2 to 9
  81.         xc=(l/ndh)*log10(c)
  82.         xc=(x2-xc)%1
  83.         'DRAW('xc','y0','xc','y1')'
  84.         end
  85.         x2 = (x1)-i*(l/ndh)
  86.         x2 = x2%1
  87.     end
  88.     end
  89.     otherwise call quitter
  90. end
  91.  
  92. 'ASK("Vertical axis"+CHR(10)+"Number of decades?")'
  93. ndv = result
  94. if ndv<=0 then call quitter
  95.  
  96. y1=y0+h
  97. x1=x0+ndh*(l%ndh)
  98. /* Drawing borders */
  99. 'DRAWMODE(-2):DRAW('x0','y0','x1','y0'):DRAW('x0','y1','x0','y0')'
  100.  
  101. 'SELECT("Scale type"+CHR(10)+"1- Linear"+CHR(10)+"2- Logarithm"+CHR(10)+"3- Antilog")'
  102. tt=result
  103.  
  104. /* Horizontal lines */
  105. select
  106.     when tt=1 then do
  107.     do i=1 to ndv
  108.         y2 = (y0)+i*(h/ndv)
  109.         y2 = y2%1
  110.         'DRAWMODE(-1)'
  111.         do c=1 to 9
  112.         yc = y2-(h/ndv)/10*c
  113.         yc=yc%1
  114.         'DRAW('x0','yc','x1','yc')'
  115.         end
  116.         'DRAWMODE(-2):DRAW('x0','y2','x1','y2')'
  117.     end
  118.     end
  119.     when tt=2 then do
  120.     if ~show('L','rexxmathlib.library') then
  121.        call addlib('rexxmathlib.library',0,-30)
  122.     y2=y1
  123.     do i=1 to ndv
  124.         'DRAWMODE(-2):DRAW('x0','y2','x1','y2'):DRAWMODE(-1)'
  125.         do c=2 to 9
  126.         yc=(h/ndv)*log10(c)
  127.         yc=(y2-yc)%1
  128.         'DRAW('x0','yc','x1','yc')'
  129.         end
  130.         y2 = y1-i*(h/ndv)
  131.         y2 = y2%1
  132.     end
  133.     end
  134.     when tt=3 then do
  135.     if ~show('L','rexxmathlib.library') then
  136.        call addlib('rexxmathlib.library',0,-30)
  137.  
  138.     y2=y0
  139.  
  140.     do i=1 to ndv
  141.         'DRAWMODE(-1)'
  142.         do c=2 to 9
  143.         yc=(h/ndv)*log10(c)
  144.         yc=(y2+yc)%1
  145.         'DRAW('x0','yc','x1','yc')'
  146.         end
  147.         y2 = (y0)+i*(h/ndv)
  148.         y2 = y2%1
  149.         'DRAWMODE(-2):DRAW('x0','y2','x1','y2')'
  150.     end
  151.     end
  152.     otherwise call quitter
  153. end
  154. call quitter
  155.  
  156. minima: procedure
  157.     parse arg v1,v2
  158.     if v1<v2 then return v1
  159.     return v2
  160. end
  161.  
  162. maxima: procedure
  163.     parse arg v1,v2
  164.     if v1>v2 then return v1
  165.     return v2
  166. end
  167.  
  168. quitter: procedure expose clip
  169.     if clip>=0 then 'CLIPUNIT('clip')'
  170.     exit
  171.  
  172. syntax:
  173. erreur=RC
  174. 'MESSAGE("Script grid.AmiCAD"+CHR(10)+"Syntax error"+CHR(10)+"in line 'SIGL'"+CHR(10)+"'errortext(erreur)'")'
  175. exit
  176.  
  177. error:
  178. 'MESSAGE("Script grid.AmiCAD"+CHR(10)+"Error in line 'SIGL'")'
  179. call quitter
  180.